/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servermba.mdb;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author lekhanhduy
 */
public class ConnectDB {

    public static Connection openConnect() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.err.println("Khong tim thay jdbc");
            return null;
        }
        Connection connection;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mba", "root", "khanhduybkhn");
        } catch (SQLException e) {
            System.err.println("Ket noi khong thanh cong");
            return null;
        }
        if(connection!=null)
            return connection;
        else
            return null;
    }

    public static void closeConnect(Connection conn) throws SQLException {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                System.err.println("Loi khi dong ket noi!");
            }
        }
    } 
}
